SFHelper.h

Go to the documentation of this file.
00001 #ifndef SFHELPER
00002 
00009 #define SFHELPER
00010 
00014 namespace SF{
00026 class CResource
00027 {
00028         public:
00031         static CResource & GetInstance(){
00032                 if(m_pResource.get() == NULL){
00033                         ATL::CComAutoCriticalSection p;
00034                         p.Init();
00035                         if(p.Lock() == S_OK && m_pResource.get() == NULL){
00036                                 m_pResource = std::auto_ptr<CResource>(new CResource());
00037                         }
00038                 }
00039                 return (*m_pResource);
00040         };
00041 
00045         static CResource * GetInstancePtr(){
00046                 if(m_pResource.get() == NULL){
00047                         ATL::CComAutoCriticalSection p;
00048                         if(p.Lock() == S_OK && m_pResource.get() == NULL){
00049                                 m_pResource = std::auto_ptr<CResource>(new CResource());
00050                         }
00051                 }
00052                 return m_pResource.get();
00053         };
00054 
00059         LPCTSTR GetString(UINT nID){
00060                 return m_str.Lookup(nID)->GetBuffer();
00061         };
00062 
00065         ~CResource() {
00066                 for(int i = 0;i < m_str.GetSize();i++){
00067                         delete m_str.Lookup(i);
00068                 }
00069                 m_str.RemoveAll();
00070         };
00071 
00072         protected:
00074         CResource() {
00075                 init();
00076         };
00077 
00078 
00079         private:
00082         void init()
00083         {
00084                 ::EnumResourceNames(
00085                           _Module.GetResourceInstance(),// Resource Handle モジュールのハンドル
00086                           RT_STRING,            // Resource Type リソースタイプ
00087                           (ENUMRESNAMEPROC)(&EnumResNameProc),  // CallBack Function Pointer コールバック関数
00088                           (LPARAM)this              // this pointer 
00089                           );
00090 
00091         };
00092         
00095         static BOOL CALLBACK EnumResNameProc(
00096                  HMODULE hModule,   
00097                  LPCTSTR lpszType,  
00098                  LPTSTR lpszName,   
00099                 LONG_PTR lParam    
00100                 )
00101         {
00102                 ATLASSERT((reinterpret_cast<UINT>(lpszName) & 0xffff0000) == 0);
00103                 UINT nID = (reinterpret_cast<UINT>(lpszName) - 1) * 16;
00104                 for (UINT j = 0; j < 15; j++ ) {
00105                         CString * _pstr = new CString();
00106                         if(_pstr->LoadString(_Module.GetResourceInstance(),nID + j)){
00107                                 ((CResource *)lParam)->m_str.Add(nID + j,_pstr);
00108                         } else {
00109                                 delete _pstr;
00110                         }
00111                 }
00112                 return TRUE;
00113         };
00114 
00115         CSimpleMap<UINT,CString*> m_str; 
00116         static std::auto_ptr<CResource> m_pResource;
00117 
00118 };
00119 }
00124 #define RES_STR(id) SF::CResource::GetInstance().GetString(id)
00125 
00129 #define COMMAND_ID_HANDLER_EX2(id, func) \
00130         if (uMsg == WM_COMMAND && id == LOWORD(wParam)) \
00131         { \
00132                 SetMsgHandled(TRUE); \
00133                 func(); \
00134                 lResult = 0; \
00135                 if(IsMsgHandled()) \
00136                         return TRUE; \
00137         }
00138 #endif

Generated on Mon Nov 24 18:31:23 2003 for PsycleWTL by doxygen 1.3.4